<?php
$username=$_GET['username'];
$costo=$_GET['price'];
$filmId=$_GET['filmId'];
$tempoNoleggio=$_GET['time'];
$data=date("d.m.y");
$db = new DBManager ( 'localhost', 'root', '', 'iumus' );
$query="SELECT saldo FROM utente WHERE username='".$username."';";
$result=$db->executeQuery($query);
$row=mysql_fetch_array($result);
$saldoPrecedente=$row['saldo'];
if($saldoPrecedente<$costo)
	return;
$query='INSERT INTO `filmnoleggio` (`idUser`,`idFilm`,`DataNoleggio`,`DurataNoleggio`) VALUES ('."'".$username."', "."'".$filmId."', "."'".$data."', "."'".$tempoNoleggio."');";
$queryUpdate="UPDATE utente SET saldo=".($saldoPrecedente-$saldo)." WHERE username='".$username."';";
$db->executeQuery ($query);
$db->executeQuery ($queryUpdate);
?>